package com.XinYun.Library.modules.borrow;

import com.XinYun.Library.modules.borrow.Dao.borrowDaoImpl;
import com.XinYun.Library.utils.HTTPRequestUtils.HTTPRequestUtil;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;


@WebServlet(name = "returnServlet", value = "/returnServlet")
public class returnServlet extends HttpServlet {
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String json = HTTPRequestUtil.getBody(request);
            //将JSON字符转化为JAVA对象
        System.out.println(request.getContextPath());
        JSONObject jsonObject = JSONObject.parseObject(json);
        String value = jsonObject.getString("sid");
        String sql="select borrow_count,return_count,exceedtime_count,isbanned from user_loandata where sid = ?";
        borrowDaoImpl bD=new borrowDaoImpl();
        Map<Object,Object> data1 = new HashMap<>();
        try {
            bD.getALL(sql,value);
            data1.put("code",1);
            data1.put("借书信息",bD.getALL(sql,value));
        } catch (SQLException e) {
            data1.put("code",-1);
            data1.put("message","未获取成功");
            throw new RuntimeException(e);
        }
        response.getWriter().write(data1.toString());
        response.getWriter().write(jsonObject.toString());
    }
}
